/********************************************************************************
 *      Copyright:  (C) 2024 linuxer<linuxer@email.com>
 *                  All rights reserved.
 *
 *       Filename:  packet.h
 *    Description:  This file
 *
 *        Version:  1.0.0(01/04/24)
 *         Author:  linuxer <linuxer@email.com>
 *      ChangeLog:  1, Release initial version on "01/04/24 13:54:46"
 *
 ********************************************************************************/
#ifndef PACKET_H
#define PACKET_H
#include <stdbool.h>
#include "cJSON.h"
#include "dictionary.h"
#define BUF_SIZE 128

typedef struct ReportInfo
{
	float			humidity;
    float           temperature;
    char            serial[32];
    struct tm       time;
	char			cur_time[32];
}ReportInfo;

typedef struct mqtt_report_s
{
    char    hostname[BUF_SIZE] ;
    int     port ;
    char    username[BUF_SIZE] ;
    char    passwd[BUF_SIZE] ;
    char    clientid[BUF_SIZE] ;
    char    topic[BUF_SIZE] ;
    int     Qos;
    char    updata[BUF_SIZE] ;
    char    state[BUF_SIZE] ;
    char    reported[BUF_SIZE] ;
    char    method[BUF_SIZE] ;
    char    jsonid[BUF_SIZE] ;
    char    identifier[BUF_SIZE] ;
    char	identifier1[BUF_SIZE];
	char    version[BUF_SIZE] ;
    bool    session;
    int     keep_alive_interval;
}mqtt_report_t;


int get_mqttdata(char *ini_path, mqtt_report_t *mqtt, int option);

int parser_config(dictionary *ini, mqtt_report_t **mqtt, char *con_plat, char *send_plat);
#if 0
int ali_conf(mqtt_conf_t *conf, dictionary *ini);

int tenxun_conf(mqtt_conf_t *conf, dictionary *ini);

int huawei_conf(mqtt_conf_t *conf, dictionary *ini);
#endif

int pack_data(mqtt_report_t *mqtt, char *msg,int size, int option);

int pack_json_ali(mqtt_report_t *mqtt, cJSON **root, ReportInfo report_info);

int pack_json_tenxun(mqtt_report_t *mqtt, cJSON **root, ReportInfo report_info);

int pack_json_huawei(mqtt_report_t *mqtt, cJSON **root, ReportInfo report_info);
/*
 *+------------------------------------------------------------------------------+
 *|     function:  packet_string_pack
 *|  description:  packaging the information on temperature
 *|   input args:  report_info : the pointer of ReportInfo struct
                   pack_buf:     the pointer of message buffer
                   size:         the size of buffer
 *|  output args:  the information of temperature
 *| return value:  <0: fail to packaging   =0: ok
 *+------------------------------------------------------------------------------+
 */
int packet_string_pack(ReportInfo *report_info, char *pack_buf, int size);


/*
 *+------------------------------------------------------------------------------+
 *|     function:  packet_string_pack
 *|  description:  packaging the information on temperature and converting it to json format
 *|   input args:  report_info : the pointer of ReportInfo struct
                   pack_buf:     the pointer of message buffer
                   size:         the size of buffer
 *|  output args:  the information of temperature
 *| return value:  <0: fail to packaging   =0: ok
 *+------------------------------------------------------------------------------+
 */
int packet_json_pack(ReportInfo *report_info, char *pack_buf, int size);

#endif
